<?php
/*
 * Krpano100 初始化常用类库
 * ============================================================================
 * 技术支持：2015-2099 成都世纪川翔科技有限公司
 * 官网地址: http://www.krpano100.com
 * ----------------------------------------------------------------------------
 * $Author: yuanjiang 932625974#qq.com $
 * $Id: init.php 28028 2016-04-27Z yuanjiang $
*/
if(!defined('IN_T')){
	die('hacking attempt');
}

//session设置
//session_set_cookie_params(0,'/','.krpano100.com');   //设置session作用域
session_start();

//自定义企业后台目录，目录名须与此一致
define('COMPANY_PATH','company/admin');

//程序所在根目录
define('ROOT_PATH',str_replace(COMPANY_PATH.'/include/init.php','',str_replace('\\', '/', __FILE__)));

/* 配置文件 */
require_once ROOT_PATH.'config/config.php';

//smarty配置文件
require_once ROOT_PATH.'source/include/smarty/smarty.config.php';

/* 常量 */
require_once ROOT_PATH.'source/include/inc_constant.php';

/* 语言库 */
require_once ROOT_PATH.'source/language/common.php';
/* 语言库 */
require_once ROOT_PATH.COMPANY_PATH.'/../language/common.php';

/* 基本类 */
require_once ROOT_PATH.'source/include/cls_json.php';
require_once ROOT_PATH.'source/include/cls_db.php';
require_once ROOT_PATH.'source/include/cls_base.php';
require_once ROOT_PATH.'source/include/cls_common.php';   //Common方法
require_once ROOT_PATH.'source/include/cls_transaction.php';   //Transaction方法
require_once ROOT_PATH.'source/include/cls_curl.php';
require_once ROOT_PATH.COMPANY_PATH.'/include/lib_main.php';

/* 初始化基本类 */
$Json = new Json;
$Db = MyPDO::getInstance($db_host,$db_user,$db_pass,$db_name,$db_charset);
$Base = new Base($db_name,$db_prefix);

/* 将登录信息输出到前台 */
$company = array(
 'id' => intval($_SESSION['company']['id']),
 'name' => isset($_SESSION['company']['name']) ? $_SESSION['company']['name']: '',
 'is_admin' => intval($_SESSION['company']['is_admin']),  //是否是管理员
 'p_id' => intval($_SESSION['company']['p_id']),
 'priv' => $_SESSION['company']['priv'],
 'c_id'=>$_SESSION['company']['c_id']
);

/* 7天内免登录 */
if($_COOKIE['company']['id']>0 && $company['id']<1){ 
   $sql = "select id,name,p_id,privileges,passwd from ".$Base->table('company')." where id=".$_COOKIE['company']['id']."";
   $u = $Db->query($sql,"Row");
   $u['priv'] = $Json->decode($u['privileges']);
   $u['c_id'] = get_company_id();
   $hashcode = Common::encrypt($u['name'].$u['passwd']);
   if($hashcode==$_COOKIE['company']['hashcode']){
     unset($u['passwd']);
	 $_SESSION['company'] = $company = $u;
   }
}

$tp->assign('company',$company);

/* 语言变量输出到前台 */
Transaction::get_site_config();	//提取站点配置
$_lang['company_path'] = COMPANY_PATH;
$tp->assign('_lang',$_lang);

//重新赋值模板目录
$tp->template_dir = ROOT_PATH.COMPANY_PATH.'/template';

?>